home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / tde210.zip / TDESTR.H < prev    next >
C/C++ Source or Header  |  1992-11-13  |  23KB  |  594 lines

  1. /*
  2.  * New editor name:  tde, the Thomson-Davis Editor.
  3.  * Author:           Frank Davis
  4.  * Date:             June 5, 1991
  5.  *
  6.  * This modification of Douglas Thomson's code is released into the
  7.  * public domain, Frank Davis.  You may distribute it freely.
  8.  *
  9.  * This file contains define's and structure declarations common to all
  10.  * editor modules.  It should be included in every source code module.
  11.  */
  12.  
  13. #define MAX_COLS            80  /* widest screen ever used */
  14. #define MAX_LINES           24  /* highest screen ever used */
  15. #define BUFF_SIZE         1042  /* buffer size for lines */
  16. #define MAX_LINE_LENGTH   1040  /* longest line allowed in file */
  17. #define UNDO_MAX            10  /* maximum number of lines in undo buffer */
  18. #define FNAME_LENGTH        45  /* maximum file name length in lite bar */
  19. #define NO_MARKERS           3  /* maximum no. of markers */
  20.  
  21.  
  22. /*
  23.  * general defines.
  24.  */
  25. #define ERROR           (-1)          /* abnormal termination */
  26. #define OK              0             /* normal termination */
  27. #define TRUE            1             /* logical true */
  28. #define FALSE           0             /* logical false */
  29.  
  30.  
  31. #define MAX_KEYS           256  /* number of special keys recognized by TDE */
  32. #define STROKE_LIMIT      1024  /* number of key strokes in playback buffer */
  33. #define STACK_UNDERFLOW      1  /* code for underflowing macro stack */
  34. #define STACK_OVERFLOW       2  /* code for overflowing macro stack */
  35. #define SAS_P                20 /* number of sas pointers to tokens */
  36.  
  37.  
  38. /*
  39.  * special cases for keyboard mapping -  see bottom of main.c
  40.  */
  41. #define RTURN           262           /* Return key = 262 */
  42. #define CONTROL_Z       26            /* Control z  = 26 or DOS eof character */
  43. #define ESC             258           /* Escape key = 258 */
  44. #define CONTROL_BREAK   269           /* Control-Break = 269 */
  45.  
  46.  
  47. /*
  48.  * The following defines are used by the "error" function, to indicate
  49.  *  how serious the error is.
  50.  */
  51. #define WARNING         1    /* user must acknowledge, editor continues */
  52. #define FATAL           2    /* editor aborts - very rare! */
  53. #define INFO            3    /* display message, acknowledge, continue */
  54.  
  55.  
  56. /*
  57.  * define the type of block marked by user and block actions
  58.  */
  59. #define NOTMARKED       0    /* block type undefined */
  60. #define BOX             1    /* block marked by row and column */
  61. #define LINE            2    /* block marked by begin and end lines */
  62. #define STREAM          3    /* block marked by begin and end characters */
  63.  
  64. #define MOVE            1
  65. #define DELETE          2
  66. #define COPY            3
  67. #define KOPY            4
  68. #define FILL            5
  69. #define OVERLAY         6
  70. #define NUMBER          7
  71. #define SWAP            8
  72.  
  73. #define LEFT            1
  74. #define RIGHT           2
  75.  
  76. #define ASCENDING       1
  77. #define DESCENDING      2
  78.  
  79.  
  80. /*
  81.  * three types of ways to update windows
  82.  */
  83. #define LOCAL           1
  84. #define NOT_LOCAL       2
  85. #define GLOBAL          3
  86.  
  87. #define CURLINE         1
  88. #define NOTCURLINE      2
  89.  
  90.  
  91. /*
  92.  * search/replace flags.
  93.  */
  94. #define CLR_SEARCH      0
  95. #define WRAPPED         1
  96. #define SEARCHING       2
  97.  
  98. #define IGNORE          1
  99. #define MATCH           2
  100.  
  101. #define PROMPT          1
  102. #define NOPROMPT        2
  103.  
  104. #define FORWARD         1
  105. #define BACKWARD        2
  106.  
  107. #define BEGIN           1
  108. #define END             2
  109.  
  110.  
  111. #define BEGINNING       1
  112. #define CURRENT         2
  113.  
  114.  
  115. /*
  116.  * word wrap flag.
  117.  */
  118. #define NO_WRAP         0
  119. #define FIXED_WRAP      1
  120. #define DYNAMIC_WRAP    2
  121.  
  122. /*
  123.  * date and time formats
  124.  */
  125. #define MM_DD_YY        0
  126. #define DD_MM_YY        1
  127. #define YY_MM_DD        2
  128. #define MM_DD_YYYY      3
  129. #define DD_MM_YYYY      4
  130. #define YYYY_MM_DD      5
  131.  
  132. #define _12_HOUR        0
  133. #define _24_HOUR        1
  134.  
  135.  
  136. /*
  137.  * used in interrupt 0x21 function xx for checking file status
  138.  */
  139. #define EXIST           0
  140. #define WRITE           2
  141. #define READ            4
  142. #define READ_WRITE      6
  143.  
  144. #define NORMAL          0x00
  145. #define READ_ONLY       0x01
  146. #define HIDDEN          0x02
  147. #define SYSTEM          0x04
  148. #define VOLUME_LABEL    0x08
  149. #define SUBDIRECTORY    0x10
  150. #define ARCHIVE         0x20
  151.  
  152. /*
  153.  * critical error def's
  154.  */
  155. #define RETRY           1
  156. #define FAIL            3
  157.  
  158.  
  159. /*
  160.  * flags used for opening files to write either in binary or text mode.
  161.  * crlf is for writing files in text mode - Operating System converts
  162.  * lf to crlf automatically on output.  in binary mode, lf is not translated.
  163.  */
  164. #define CRLF            1
  165. #define LF              2
  166.  
  167.  
  168. /*
  169.  * characters used in tdeasm.c to display eol and column pointer in ruler
  170.  */
  171. #define EOL_CHAR        0x11
  172. #define RULER_CHAR      0x19
  173.  
  174.  
  175. /*
  176.  * character used two separate vertical screens
  177.  */
  178. #define VERTICAL_CHAR   0xba
  179.  
  180.  
  181. /*
  182.  * cursor size
  183.  */
  184. #define SMALL_INS       0
  185. #define BIG_INS         1
  186.  
  187.  
  188. /*
  189.  * possible answers to various questions - see get_yn, get_ynaq and get_oa
  190.  */
  191. #define A_YES           1
  192. #define A_NO            2
  193. #define A_ALWAYS        3
  194. #define A_QUIT          4
  195. #define A_ABORT         5
  196. #define A_OVERWRITE     6
  197. #define A_APPEND        7
  198.  
  199. /*
  200.  * The following defines specify which video attributes give desired
  201.  *  effects on different display devices.
  202.  * REVERSE is supposed to be reverse video - a different background color,
  203.  *  so that even a blank space can be identified.
  204.  * HIGH is supposed to quickly draw the user's eye to the relevant part of
  205.  *  the screen, either for a message or for matched text in find/replace.
  206.  * NORMAL is supposed to be something pleasant to look at for the main
  207.  *  body of the text.
  208.  */
  209. #define VIDEO_INT       0x10
  210.  
  211. #define HERC_REVERSE    0x70
  212. #define HERC_UNDER      0x01
  213. #define HERC_NORMAL     0x07
  214. #define HERC_HIGH       0x0f
  215.  
  216. #define COLOR_HEAD      0x4b
  217. #define COLOR_TEXT      0x07
  218. #define COLOR_MODE      0x17
  219. #define COLOR_BLOCK     0x71
  220. #define COLOR_MESSAGE   0x0f
  221. #define COLOR_HELP      0x1a
  222. #define COLOR_DIAG      0x0e
  223. #define COLOR_EOF       0x09
  224. #define COLOR_CURL      0x0f
  225. #define COLOR_RULER     0x02
  226. #define COLOR_POINTER   0x0a
  227.  
  228. #define COLOR_80        3
  229. #define MONO_80         7
  230.  
  231. #define VGA             3
  232. #define EGA             2
  233. #define CGA             1
  234. #define MDA             0
  235.  
  236.  
  237. #define SAS_DELIMITERS  " \n"
  238.  
  239. /*
  240.  * Some systems (like the PC) require a special kind of pointer for
  241.  *  arrays or structures larger than 64K.  For Microsoft C compilers, I handle
  242.  *  the special pointer arithmetic internally.  See the functions in tdeasm.c
  243.  *  for those special pointer routines.
  244.  */
  245. #ifdef __TURBOC__
  246.    typedef char huge *text_ptr;
  247. #elif __MSC__
  248.    typedef char far * text_ptr;
  249. #else
  250.    typedef char *text_ptr;
  251. #endif
  252.  
  253.  
  254. struct vcfg {
  255.    int color;
  256.    int rescan;
  257.    int mode;
  258.    int far *videomem;
  259. };
  260.  
  261.  
  262. /*
  263.  * structure used in directory list.
  264.  */
  265. typedef struct {
  266.    char fname[14];              /* file name */
  267.    long fsize;                  /* file size in bytes */
  268. } FTYPE;
  269.  
  270.  
  271. /*
  272.  * stuff we need to know about how to display a directory listing.
  273.  */
  274. typedef struct {
  275.    int  row;                    /* absolute row to display dir box */
  276.    int  col;                    /* absolute column to display dir box */
  277.    int  wid;                    /* absolute number of columns in dir box */
  278.    int  hgt;                    /* absolute number of rows in dir box */
  279.    int  max_cols;               /* number of columns of files in box */
  280.    int  max_lines;              /* number of lines of files in box */
  281.    int  cnt;                    /* file count */
  282.    int  cols;                   /* logical number of columns in list */
  283.    int  lines;                  /* logical number of rows in list */
  284.    int  prow;                   /* logical number of rows in partial row */
  285.    int  vcols;                  /* number of virtual columns, if any */
  286.    int  nfiles;                 /* number of files on screen */
  287.    int  avail;                  /* number of available slots for files */
  288.    int  select;                 /* current file under cursor */
  289.    int  flist_col[5];           /* offset from col to display each column */
  290. } DIRECTORY;
  291.  
  292.  
  293. typedef struct {
  294.    int  pattern_length;                 /* number of chars in pattern */
  295.    int  search_defined;                 /* search pattern defined? */
  296.    unsigned char pattern[MAX_COLS];     /* search pattern */
  297.    int  forward_md2;                    /* forward mini-delta2 */
  298.    int  backward_md2;                   /* backward mini-delta2 */
  299.    char skip_forward[256];              /* boyer array for forward searches */
  300.    char skip_backward[256];             /* boyer array for back searches */
  301. } boyer_moore_type;
  302.  
  303.  
  304. /*
  305.  * "mode_infos" contain the editor mode variables.  The configuration
  306.  *  utility modifies this structure to custimize the start-up tde
  307.  *  configuration
  308.  */
  309. typedef struct {
  310.    int  color_scheme;           /* color to start out with */
  311.    int  sync;                   /* sync the cursor movement command? */
  312.    int  sync_sem;               /* sync the cursor movement command? */
  313.    int  record;                 /* are we recording keystrokes? */
  314.    int  insert;                 /* in insert mode? */
  315.    int  indent;                 /* in auto-indent mode? */
  316.    int  ptab_size;              /* physical tab stops */
  317.    int  ltab_size;              /* logical tab stops */
  318.    int  smart_tab;              /* smart tab mode on or off? */
  319.    int  inflate_tabs;           /* inflate tabs?  T or F */
  320.    int  search_case;            /* consider case? IGNORE or MATCH */
  321.    int  enh_kbd;                /* type of keyboard */
  322.    int  cursor_size;            /* insert cursor big or small? */
  323.    char *eof;                   /* message to display at end of file */
  324.    int  control_z;              /* write ^Z - t or f */
  325.    int  crlf;                   /* <cr><lf> toggle CRLF or LF */
  326.    int  trailing;               /* remove trailing space? T or F */
  327.    int  show_eol;               /* show lf at eol? T or F */
  328.    int  word_wrap;              /* in word wrap mode? */
  329.    int  left_margin;            /* left margin */
  330.    int  parg_margin;            /* column for 1st word in paragraph */
  331.    int  right_margin;           /* right margin */
  332.    int  do_backups;             /* create backup or ".bak" files? T or F */
  333.    int  ruler;                  /* show ruler at top of window? T or F */
  334.    int  date_style;             /* date style for date and time stamp */
  335.    int  time_style;             /* time style for date and time stamp */
  336. } mode_infos;
  337.  
  338.  
  339. /*
  340.  * "displays" contain all the status information about what attributes are
  341.  *  used for what purposes, which attribute is currently set, and so on.
  342.  * The editor only knows about one physical screen.
  343.  */
  344. typedef struct {
  345.    int nlines;                  /* lines on display device */
  346.    int ncols;                   /* columns on display device */
  347.    int line_length;             /* length of longest line */
  348.    int mode_line;               /* line to display editor modes - fmd */
  349.    int head_color;              /* file header color */
  350.    int text_color;              /* text area color */
  351.    int mode_color;              /* mode line color - footer */
  352.    int block_color;             /* hilited area of blocked region */
  353.    int message_color;           /* color of editor messages */
  354.    int help_color;              /* color of help screen */
  355.    int diag_color;              /* color for diagnostics in mode line */
  356.    int eof_color;               /* color for end of file line */
  357.    int curl_color;              /* color of cursor line */
  358.    int ruler_color;             /* color of ruler line */
  359.    int ruler_pointer;           /* color of ruler pointer */
  360.    int hilited_file;            /* color of current file in dir list */
  361.    int adapter;                 /* VGA, EGA, CGA, or MDA? */
  362.    unsigned int overw_cursor;   /* hi part = top scan line, lo part = bottom */
  363.    unsigned int insert_cursor;  /* hi part = top scan line, lo part = bottom */
  364.    char far *display_address;   /* address of display memory */
  365. } displays;
  366.  
  367.  
  368. /*
  369.  * "WINDOW" contains all the information that is unique to a given
  370.  *  window.
  371.  */
  372. typedef struct s_window {
  373.    struct s_file_infos *file_info;       /* file in window */
  374.    text_ptr cursor;             /* start of line containing cursor */
  375.    int  ccol;                   /* column cursor logically in */
  376.    int  rcol;                   /* column cursor actually in */
  377.    int  bcol;                   /* base column to start display */
  378.    int  cline;                  /* line cursor logically in */
  379.    long rline;                  /* real line cursor in */
  380.    int  top_line;               /* top line in window */
  381.    int  bottom_line;            /* bottom line in window */
  382.    int  vertical;               /* boolean. is window split vertically? */
  383.    int  start_col;              /* starting column on physical screen */
  384.    int  end_col;                /* ending column on physical screen */
  385.    int  page;                   /* no. of lines to scroll for one page */
  386.    int  visible;                /* window hidden or visible */
  387.    int  letter;                 /* window letter */
  388.    int  ruler;                  /* show ruler in this window? */
  389.    char ruler_line[MAX_COLS+2]; /* ruler for this window */
  390.    struct s_window *next;       /* next window in doubly linked list */
  391.    struct s_window *prev;       /* previous window in doubly linked list */
  392. } WINDOW;
  393.  
  394.  
  395. /*
  396.  * struct for find first and find next functions.  see DOS technical ref
  397.  * manuals for more info on DTA structures.
  398.  */
  399. typedef struct {
  400.    char          reserved[21];
  401.    unsigned char attrib;
  402.    unsigned      time;
  403.    unsigned      date;
  404.    long          size;
  405.    char          name[13];
  406. } DTA;
  407.  
  408.  
  409. /*
  410.  * "status_infos" contain all the editor status information that is
  411.  *  global to the entire editor (i.e. not dependent on the file or
  412.  *  window)
  413.  */
  414. typedef struct {
  415.    WINDOW *current_window;      /* current active window */
  416.    struct s_file_infos *current_file; /* current active file */
  417.    struct s_file_infos *file_list; /* all active files */
  418.    WINDOW *window_list;         /* all active windows */
  419.    int  window_count;           /* number of windows - displayed and hidden */
  420.    int  file_count;             /* number of files currently open */
  421.    text_ptr start_mem;          /* first char in main text buffer */
  422.    text_ptr end_mem;            /* last char in main text buffer used+1 */
  423.    text_ptr temp_end;           /* temporary end_mem marker */
  424.    text_ptr max_mem;            /* last char available for storage (+1) */
  425.    int  arg;                    /* current argument pointer */
  426.    int  found_first;            /* have we found the first file? */
  427.    int  argc;                   /* argument count */
  428.    char **argv;                 /* argument variables - same as *argv[] */
  429.    char path[MAX_COLS];         /* path for files on command line */
  430.    DTA  dta;                    /* disk transfer address for find next */
  431.    int  sas_defined;            /* has search and seize been defined */
  432.    int  sas_arg;                /* current argument pointer */
  433.    int  sas_argc;               /* argument count */
  434.    char **sas_argv;             /* argument variables - same as *argv[] */
  435.    char sas_tokens[MAX_COLS];   /* storage for file tokens */
  436.    char sas_path[MAX_COLS];     /* path for files on search list */
  437.    char *sas_arg_pointers[SAS_P]; /* array of pointers to tokens in sas_path */
  438.    int  sas_found_first;        /* have we found the first file? */
  439.    DTA  sas_dta;                /* disk transfer address for find next */
  440.    text_ptr sas_text;           /* pointer to found text */
  441.    int  marked;                 /* has block been marked? */
  442.    int  prompt_line;            /* line to display cursor */
  443.    int  prompt_col;             /* column to display cursor */
  444.    struct s_file_infos *marked_file;  /* pointer to file w/ marked block */
  445.    char rw_name[MAX_COLS];      /* name of last file read or written */
  446.    char pattern[MAX_COLS];      /* last search pattern */
  447.    char subst[MAX_COLS];        /* last substitute text */
  448.    int  replace_flag;           /* prompt or noprompt b4 replacing */
  449.    int  overlap;                /* overlap between pages for page up etc */
  450.    text_ptr buff_line;          /* address of line in line_buff */
  451.    int  copied;                 /* has line been copied to file? */
  452.    char line_buff[BUFF_SIZE*2+8]; /* for currently edited line */
  453.    char tabout_buff[BUFF_SIZE+8]; /* for exanding tabs */
  454.    int  command;                /* function of key just entered */
  455.    int  key_pressed;            /* key pressed by user */
  456.    int  wrapped;                /* is the wrapped message on mode line? */
  457.    int  stop;                   /* stop indicator */
  458.    int  control_break;          /* control break pressed? */
  459.    int  recording_key;          /* key we are assigning keystrokes to */
  460.    int  stroke_count;           /* free keys in stroke buffer */
  461.    int  macro_next;             /* pointer to next key in macro */
  462.    int  macro_executing;        /* flag set if macro is executing */
  463.    int  mstack_pointer;         /* pointer to macro stack */
  464.    int  current_macro;          /* index of currently executing macro */
  465.    text_ptr top_stack;          /* pointer to top of stack */
  466.    text_ptr max_stack;          /* pointer to last possible char in stack */
  467.    text_ptr bot_stack;          /* pointer to bottom of stack */
  468.    char undo_buffer[UNDO_MAX][BUFF_SIZE]; /* room for last 10 changed lines */
  469. } status_infos;
  470.  
  471.  
  472. /*
  473.  * marker structure used to save file positions.
  474.  */
  475. typedef struct {
  476.    long rline;                  /* real line of marker */
  477.    int  rcol;                   /* real column of marker */
  478.    int  ccol;                   /* logical column of marker */
  479.    int  bcol;                   /* base column of marker */
  480.    int  marked;                 /* boolean:  has this marker been set? */
  481. } MARKER;
  482.  
  483.  
  484. /*
  485.  * "file_infos" contain all the information unique to a given file
  486.  */
  487. typedef struct s_file_infos {
  488.    text_ptr start_text;        /* first char in file */
  489.    text_ptr end_text;          /* last char in file (+1) */
  490.    MARKER marker[NO_MARKERS];  /* number of file markers */
  491.    long length;                /* number of lines in file */
  492.    int  modified;              /* file has been modified since save? */
  493.    int  dirty;                 /* file in window modified? */
  494.    int  new_file;              /* is current file new? */
  495.    int  backed_up;             /* has ".bak" file been created? */
  496.    char file_name[MAX_COLS];   /* name of current file being edited */
  497.    char backup_fname[MAX_COLS];/* name of backup of current file */
  498.    int block_type;             /* block type - line or box */
  499.    text_ptr block_start;       /* beginning block position */
  500.    text_ptr block_end;         /* ending block position */
  501.    int  block_bc;              /* beginning column */
  502.    long block_br;              /* beginning row */
  503.    int  block_ec;              /* ending column */
  504.    long block_er;              /* ending row */
  505.    int  file_no;               /* file number */
  506.    int  ref_count;             /* no. of windows referring to file */
  507.    int  next_letter;           /* next window letter */
  508.    unsigned int  file_attrib;  /* file attributes (rwx etc) */
  509.    struct s_file_infos *next;  /* next file in doubly linked list */
  510.    struct s_file_infos *prev;  /* previous file in doubly linked list */
  511. } file_infos;
  512.  
  513.  
  514. /*
  515.  * structure for recording and playing back one keystroke.
  516.  */
  517. typedef struct {
  518.   int key;      /* key assinged to this node, which may be text or function */
  519.   int next;     /* pointer to next node in macro def */
  520. } STROKES;
  521.  
  522.  
  523. /*
  524.  * structure for the macro buffer.
  525.  */
  526. typedef struct {
  527.    int  first_stroke[MAX_KEYS];         /* pointer to first key in macro */
  528.    STROKES strokes[STROKE_LIMIT];       /* buffer to hold key strokes */
  529. } MACRO;
  530.  
  531.  
  532. /*
  533.  * structure for the local macro stack in macro processor.
  534.  */
  535. typedef struct {
  536.    int key;                             /* key to begin execution in macro */
  537.    int macro;                           /* macro we were executing */
  538. } MACRO_STACK;
  539.  
  540.  
  541. /*
  542.  * structure for critical error handler.  check the flag for errors on
  543.  * each I/O call.
  544.  */
  545. typedef struct {
  546.    int  flag;                   /* 0 = no error, -1 = error */
  547.    int  code;                   /* error code from di */
  548.    int  rw;                     /* read or write operation? */
  549.    int  drive;                  /* drive number of error */
  550.    int  extended;               /* extended error code, func 0x59 */
  551.    int  class;                  /* error class */
  552.    int  action;                 /* suggested action from DOS */
  553.    int  locus;                  /* locus of error: drive, network, etc... */
  554.    int  dattr;                  /* device attribute, 0 = drive, 1 = serial */
  555.    char dname[10];              /* device name */
  556. } CEH;
  557.  
  558.  
  559. /*
  560.  * structure for sort strings
  561.  */
  562. typedef struct {
  563.    char *pivot;                 /* calloc BUFF_SIZE+2 to work properly */
  564.    char *string1;               /* calloc BUFF_SIZE+2 to work properly */
  565.    int  sort_order;
  566.    int  block_len;
  567.    int  bc;
  568.    int  ec;
  569.    unsigned long free_mem;      /* free memory between end_mem and max_mem */
  570.    int  (far * compare)( const void far *, const void far *, unsigned );
  571. } SORT;
  572.  
  573.  
  574. typedef struct {
  575.    unsigned char ignore[256];
  576.    unsigned char match[256];
  577. } SORT_ORDER;
  578.  
  579.  
  580. /*
  581.  * structure for diff.  let's only diff two windows at a time.
  582.  */
  583. typedef struct {
  584.    int       defined;                  /* initially FALSE */
  585.    int       leading;                  /* skip leading spaces t/f */
  586.    int       all_space;                /* skip all space t/f */
  587.    int       blank_lines;              /* skip blank lines t/f */
  588.    int       ignore_eol;               /* skip end of line t/f */
  589.    WINDOW    *w1;                      /* pointer to first diff window */
  590.    WINDOW    *w2;                      /* pointer to second diff window */
  591.    text_ptr  d1;                       /* pointer to text in window 1 */
  592.    text_ptr  d2;                       /* pointer to text in window 2 */
  593. } DIFF;
  594.